/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

DEFINE_GUICOLUMN_OBJECT(tablecolumn_int_text)
DEFINE_GUICOLUMN_OBJECT(tablecolumn_double_text)
DEFINE_GUICOLUMN_OBJECT(tablecolumn_string_text)
DEFINE_GUICOLUMN_OBJECT(tablecolumn_icon)

typedef struct _RowObject RowObject;
typedef struct _RowObjectClass RowObjectClass;

#define ROW_COLUMN_TYPE_INT		11
#define ROW_COLUMN_TYPE_DOUBLE		21
#define ROW_COLUMN_TYPE_STRING		31
#define ROW_COLUMN_TYPE_ICON		61

#define ROW_DATA_TYPE_INT		11
#define ROW_DATA_TYPE_DOUBLE		21
#define ROW_DATA_TYPE_STRING		31

struct _RowObject {
	GObject parent_instance;
	struct _col_datas
	{
		unsigned int col_type ;
		union _col_data
		{
			int	n ;
			double	d ;
			char	*str ;
		} col_data ;
	} *col_datas ;
	int n_columns;
};

struct _RowObjectClass {
	GObjectClass parent_class;
};

#define ROW_OBJECT_TYPE (row_object_get_type ())
#define ROW_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ROW_OBJECT_TYPE, RowObject))

G_DEFINE_TYPE(RowObject, row_object, G_TYPE_OBJECT)

static void row_object_finalize(GObject *object)
{
	RowObject *self = ROW_OBJECT(object);
	if (self->col_datas) {
		for (int i = 0; i < self->n_columns; i++) {
			if( self->col_datas[i].col_type == ROW_DATA_TYPE_STRING && self->col_datas[i].col_data.str )
				g_free(self->col_datas[i].col_data.str);
		}
		g_free(self->col_datas);
	}
	G_OBJECT_CLASS(row_object_parent_class)->finalize(object);
}

static void row_object_class_init(RowObjectClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS(klass);
	object_class->finalize = row_object_finalize;
}

static void row_object_init(RowObject *self)
{
	self->col_datas = NULL;
	self->n_columns = 0;
}

#if 0
RowObject *row_object_new(const char **strings, int n_columns)
{
	RowObject *self = g_object_new(ROW_OBJECT_TYPE, NULL);
	self->n_columns = n_columns;
	self->row_datas = g_new0(char*, n_columns);
	for (int i = 0; i < n_columns; i++) {
		self->row_datas[i] = g_strdup(strings[i]);
	}
    return self;
}
#endif

RowObject *row_object_new0(int n_columns)
{
	RowObject *self = g_object_new(ROW_OBJECT_TYPE, NULL);
	self->n_columns = n_columns;
	self->col_datas = g_new0(struct _col_datas, n_columns);
	memset( self->col_datas , 0x00 , sizeof(struct _col_datas)*n_columns );
    
	return self;
}

static void on_setup(GObject *factory, GtkListItem *target, gpointer user_data)
{
	int		column_type = GPOINTER_TO_INT(user_data) ;
	GtkWidget	*label = NULL ;
	GtkWidget	*image = NULL ;

	if( column_type == ROW_COLUMN_TYPE_INT || column_type == ROW_COLUMN_TYPE_DOUBLE || column_type == ROW_COLUMN_TYPE_STRING )
	{
		label = gtk_label_new( "" ) ;
		gtk_list_item_set_child( target , label );
	}
	else if( column_type == ROW_COLUMN_TYPE_ICON )
	{
		image = gtk_image_new() ;
		gtk_list_item_set_child( target , image );
	}

	return;
}

static void on_bind(GObject *factory, GtkListItem *target, gpointer user_data)
{
	RowObject	*row = ROW_OBJECT(gtk_list_item_get_item(target));
	int		col_index = GPOINTER_TO_INT(user_data);
	const char	*str = "";
	char		buf[41] = "" ;

	if (row && row->col_datas && col_index < row->n_columns)
	{
		if( row->col_datas[col_index].col_type == ROW_DATA_TYPE_INT )
		{
			snprintf(buf,sizeof(buf)-1,"%d",row->col_datas[col_index].col_data.n),str=buf;
			GtkWidget *label = gtk_list_item_get_child(target);
			gtk_label_set_text( GTK_LABEL(label) , str );
		}
		else if( row->col_datas[col_index].col_type == ROW_DATA_TYPE_DOUBLE )
		{
			snprintf(buf,sizeof(buf)-1,"%lf",row->col_datas[col_index].col_data.d),str=buf;
			GtkWidget *label = gtk_list_item_get_child(target);
			gtk_label_set_text( GTK_LABEL(label) , str );
		}
		else if( row->col_datas[col_index].col_type == ROW_DATA_TYPE_STRING )
		{
			str = row->col_datas[col_index].col_data.str;
			GtkWidget *widget = gtk_list_item_get_child(target);
			if( GTK_IS_LABEL(widget) )
			{
				gtk_label_set_text( GTK_LABEL(widget) , str );
			}
			else if( GTK_IS_IMAGE(widget) )
			{
				gtk_image_set_from_icon_name( GTK_IMAGE(widget) , str );
			}
		}
	}
}

static GListModel *gtk_selection_get_model( GtkSelectionModel *selection_model )
{
	if( GTK_IS_SINGLE_SELECTION(selection_model) )
		return gtk_single_selection_get_model( GTK_SINGLE_SELECTION(selection_model) );
	else
		return gtk_multi_selection_get_model( GTK_MULTI_SELECTION(selection_model) );
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_Create_guiwindow_int;
int ZlangInvokeFunction_guitable_Create_guiwindow_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						selection_modal ;
	GListStore					*list_store = NULL ;
	GtkSingleSelection				*single_selection_model = NULL ;
	GtkMultiSelection				*multi_selection_model = NULL ;
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;

	CallRuntimeFunction_int_GetIntValue( rt , in2 , & selection_modal );

	EVAL_GTK_WIDGET_NEW_IN_CREATE( list_store , g_list_store_new(ROW_OBJECT_TYPE) )
	if( selection_modal == GUISELECTION_MODAL_SINGLE )
	{
		EVAL_GTK_WIDGET_NEW_IN_CREATE( single_selection_model , gtk_single_selection_new(G_LIST_MODEL(list_store)) )
		gtk_single_selection_set_autoselect( single_selection_model , TRUE );
		gtk_single_selection_set_can_unselect( single_selection_model , TRUE );
		EVAL_GTK_WIDGET_NEW_IN_CREATE( guitable_common->gtk_widget , gtk_column_view_new(GTK_SELECTION_MODEL(single_selection_model)) )
	}
	else
	{
		EVAL_GTK_WIDGET_NEW_IN_CREATE( multi_selection_model , gtk_multi_selection_new(G_LIST_MODEL(list_store)) )
		EVAL_GTK_WIDGET_NEW_IN_CREATE( guitable_common->gtk_widget , gtk_column_view_new(GTK_SELECTION_MODEL(multi_selection_model)) )
	}
	SET_CONTROL_DEFAULT_STYLE( in1 , guitable_common->gtk_widget )

	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guitable_common->guiwindow_obj , in1 )

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_AppendColumns_vargs;
int ZlangInvokeFunction_guitable_AppendColumns_vargs( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	guint						column_count ;
	int						count ;
	int						no ;
	struct ZlangObject				*inN = NULL ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	void						*guitablecolumn_direct_prop = NULL ;
	struct ZlangDirectProperty_guiwidget_common	*guitablecolumn_common = NULL ;
	char						*column_name = NULL ;
	GtkListItemFactory				*factory = NULL ;
	GtkColumnViewColumn				*column = NULL ;

	GListModel *list_modal = gtk_column_view_get_columns( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	column_count = g_list_model_get_n_items( list_modal ) ;

	count = GetInputParameterCountInLocalObjectStack( rt ) ;
	for( no = 1 ; no <= count ; no++ )
	{
		inN = GetInputParameterInLocalObjectStack( rt , no ) ;
		if( inN == NULL )
		{
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_INTERNAL_ERROR );
		}

		guitablecolumn_direct_prop = GetObjectDirectProperty(inN) ;
		guitablecolumn_common = (struct ZlangDirectProperty_guiwidget_common *)guitablecolumn_direct_prop ;
		CallRuntimeFunction_string_GetStringValue( rt , guitablecolumn_common->zobjects_data.str_obj , & column_name , NULL );
		column_name = g_strdup( column_name ) ;

		factory = gtk_signal_list_item_factory_new() ;
		if( IsTypeOf( rt , inN , QueryGlobalObjectByObjectName(rt,ZLANG_OBJECT_guitablecolumn_int_text) ) )
		{
			g_signal_connect( factory , "setup" , G_CALLBACK(on_setup) , GINT_TO_POINTER(ROW_COLUMN_TYPE_INT) );
		}
		else if( IsTypeOf( rt , inN , QueryGlobalObjectByObjectName(rt,ZLANG_OBJECT_guitablecolumn_double_text) ) )
		{
			g_signal_connect( factory , "setup" , G_CALLBACK(on_setup) , GINT_TO_POINTER(ROW_COLUMN_TYPE_DOUBLE) );
		}
		else if( IsTypeOf( rt , inN , QueryGlobalObjectByObjectName(rt,ZLANG_OBJECT_guitablecolumn_string_text) ) )
		{
			g_signal_connect( factory , "setup" , G_CALLBACK(on_setup) , GINT_TO_POINTER(ROW_COLUMN_TYPE_STRING) );
		}
		else if( IsTypeOf( rt , inN , QueryGlobalObjectByObjectName(rt,ZLANG_OBJECT_guitablecolumn_icon) ) )
		{
			g_signal_connect( factory , "setup" , G_CALLBACK(on_setup) , GINT_TO_POINTER(ROW_COLUMN_TYPE_ICON) );
		}
		else
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_OBJECT_TYPE_INVALID );
		}
		g_signal_connect( factory , "bind" , G_CALLBACK(on_bind) , GINT_TO_POINTER(column_count+(no-1)) );
		column = gtk_column_view_column_new( column_name , factory );
		gtk_column_view_column_set_resizable( column , TRUE );
		gtk_column_view_column_set_expand( column , TRUE );
		gtk_column_view_append_column( GTK_COLUMN_VIEW(guitable_common->gtk_widget) , column );
	}

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_AppendRowDatas_vargs;
int ZlangInvokeFunction_guitable_AppendRowDatas_vargs( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	guint						column_count ;
	RowObject					*row_datas = NULL ;
	int						datas_count ;
	int						no ;
	struct ZlangObject				*inN = NULL ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						col_n ;
	double						col_d ;
	char						*col_str = NULL ;
	GListModel					*list_model = NULL ;

	GListModel *list_modal = gtk_column_view_get_columns( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	column_count = g_list_model_get_n_items( list_modal ) ;

	row_datas = row_object_new0( column_count ) ;
	if( row_datas == NULL )
	{
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
	}

	datas_count = GetInputParameterCountInLocalObjectStack( rt ) ;
	if( datas_count != column_count )
	{
		row_object_finalize( G_OBJECT(row_datas) );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETERS_COUNT_NOT_MATCHED );
	}
	for( no = 1 ; no <= datas_count ; no++ )
	{
		inN = GetInputParameterInLocalObjectStack( rt , no ) ;
		if( inN == NULL )
		{
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_INTERNAL_ERROR );
		}

		if( IsTypeOf( rt , inN , GetIntObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_int_GetIntValue( rt , inN , & col_n );
			row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_INT ;
			row_datas->col_datas[no-1].col_data.n = col_n ;
		}
		else if( IsTypeOf( rt , inN , GetDoubleObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_double_GetDoubleValue( rt , inN , & col_d );
			row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_DOUBLE ;
			row_datas->col_datas[no-1].col_data.d = col_d ;
		}
		else if( IsTypeOf( rt , inN , GetStringObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_string_GetStringValue( rt , inN , & col_str , NULL );
			row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_STRING ;
			row_datas->col_datas[no-1].col_data.str = g_strdup( col_str ) ;
			if( row_datas->col_datas[no-1].col_data.str == NULL )
			{
				row_object_finalize( G_OBJECT(row_datas) );
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
			}
		}
		else
		{
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_OBJECT_TYPE_INVALID );
		}
	}

	GtkSelectionModel *selection_model = gtk_column_view_get_model(GTK_COLUMN_VIEW(guitable_common->gtk_widget)) ;
	list_model = gtk_selection_get_model( selection_model ) ;
        g_list_store_append( G_LIST_STORE(list_model) , row_datas );
        g_object_unref( row_datas );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_AppendRowDatas_array;
int ZlangInvokeFunction_guitable_AppendRowDatas_array( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	guint						column_count ;
	RowObject					*row_datas = NULL ;
	int						datas_count ;
	int32_t						no ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in_obj = NULL ;
	int32_t						col_n ;
	double						col_d ;
	char						*col_str = NULL ;
	GListModel					*list_model = NULL ;

	GListModel *list_modal = gtk_column_view_get_columns( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	column_count = g_list_model_get_n_items( list_modal ) ;

	row_datas = row_object_new0( column_count ) ;
	if( row_datas == NULL )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
	}

	CallRuntimeFunction_array_Length( rt , in1 , & datas_count );
	if( datas_count != column_count )
	{
		row_object_finalize( G_OBJECT(row_datas) );
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETERS_COUNT_NOT_MATCHED );
	}
	for( no = 1 ; no <= datas_count ; no++ )
	{
		CallRuntimeFunction_array_Get( rt , in1 , no , & in_obj );
		if( in_obj == NULL )
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_INTERNAL_ERROR );
		}

		if( IsTypeOf( rt , in_obj , GetIntObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_int_GetIntValue( rt , in_obj , & col_n );
			row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_INT ;
			row_datas->col_datas[no-1].col_data.n = col_n ;
		}
		else if( IsTypeOf( rt , in_obj , GetDoubleObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_double_GetDoubleValue( rt , in_obj , & col_d );
			row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_DOUBLE ;
			row_datas->col_datas[no-1].col_data.d = col_d ;
		}
		else if( IsTypeOf( rt , in_obj , GetStringObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_string_GetStringValue( rt , in_obj , & col_str , NULL );
			row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_STRING ;
			row_datas->col_datas[no-1].col_data.str = g_strdup( col_str ) ;
			if( row_datas->col_datas[no-1].col_data.str == NULL )
			{
				row_object_finalize( G_OBJECT(row_datas) );
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
			}
		}
		else
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_OBJECT_TYPE_INVALID );
		}
	}

	GtkSelectionModel *selection_model = gtk_column_view_get_model(GTK_COLUMN_VIEW(guitable_common->gtk_widget)) ;
	list_model = gtk_selection_get_model( selection_model ) ;
        g_list_store_append( G_LIST_STORE(list_model) , row_datas );
        g_object_unref( row_datas );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_InsertRowDatas_int_array;
int ZlangInvokeFunction_guitable_InsertRowDatas_int_array( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	guint						column_count ;
	RowObject					*new_row_datas = NULL ;
	int						datas_count ;
	int32_t						no ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						row_no ;
	struct ZlangObject				*in_obj = NULL ;
	int32_t						col_n ;
	double						col_d ;
	char						*col_str = NULL ;
	GListModel					*list_model = NULL ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & row_no );

	list_model = gtk_column_view_get_columns( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	column_count = g_list_model_get_n_items( list_model ) ;

	new_row_datas = row_object_new0( column_count ) ;
	if( new_row_datas == NULL )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
	}

	CallRuntimeFunction_array_Length( rt , in2 , & datas_count );
	if( datas_count != column_count )
	{
		row_object_finalize( G_OBJECT(new_row_datas) );
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETERS_COUNT_NOT_MATCHED );
	}
	for( no = 1 ; no <= datas_count ; no++ )
	{
		CallRuntimeFunction_array_Get( rt , in2 , no , & in_obj );
		if( in_obj == NULL )
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_INTERNAL_ERROR );
		}

		if( IsTypeOf( rt , in_obj , GetIntObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_int_GetIntValue( rt , in_obj , & col_n );
			new_row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_INT ;
			new_row_datas->col_datas[no-1].col_data.n = col_n ;
		}
		else if( IsTypeOf( rt , in_obj , GetDoubleObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_double_GetDoubleValue( rt , in_obj , & col_d );
			new_row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_DOUBLE ;
			new_row_datas->col_datas[no-1].col_data.d = col_d ;
		}
		else if( IsTypeOf( rt , in_obj , GetStringObjectInRuntimeObjectsHeap(rt) ) )
		{
			CallRuntimeFunction_string_GetStringValue( rt , in_obj , & col_str , NULL );
			new_row_datas->col_datas[no-1].col_type = ROW_DATA_TYPE_STRING ;
			new_row_datas->col_datas[no-1].col_data.str = g_strdup( col_str ) ;
			if( new_row_datas->col_datas[no-1].col_data.str == NULL )
			{
				row_object_finalize( G_OBJECT(new_row_datas) );
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
			}
		}
		else
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_OBJECT_TYPE_INVALID );
		}
	}

	GtkSelectionModel *selection_model = gtk_column_view_get_model(GTK_COLUMN_VIEW(guitable_common->gtk_widget)) ;
	list_model = gtk_selection_get_model( selection_model ) ;
        g_list_store_insert( G_LIST_STORE(list_model) , row_no-1 , new_row_datas );
        g_object_unref( new_row_datas );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZLANG_INVOKE_FUNCTION_guiwidget_all_common_functions( table )

ZLANG_INVOKE_FUNCTION_guictl_all_common_functions( table )

ZlangInvokeFunction ZlangInvokeFunction_guitable_RemoveRow_int;
int ZlangInvokeFunction_guitable_RemoveRow_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	int32_t						row_no ;
	GListModel					*model = NULL ;
	int32_t						row_count ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & row_no );

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	model = gtk_selection_get_model( selection_model ) ;
	row_count = g_list_model_get_n_items( model ) ;
	if( row_no > row_count )
	{
		CallRuntimeFunction_bool_GetBoolValue( rt , in1 , FALSE );
		return 0;
	}
	if( row_no < 0 )
	{
		CallRuntimeFunction_bool_GetBoolValue( rt , in1 , FALSE );
		return 0;
	}

	g_list_store_remove( G_LIST_STORE(model) , row_no-1 );

	CallRuntimeFunction_bool_SetBoolValue( rt , in1 , TRUE );
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_RemoveAllRows;
int ZlangInvokeFunction_guitable_RemoveAllRows( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	GListModel					*model = NULL ;

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	model = gtk_selection_get_model( selection_model ) ;

	g_list_store_remove_all( G_LIST_STORE(model) );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_GetColumnCount;
int ZlangInvokeFunction_guitable_GetColumnCount( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						column_count ;

	GListModel *list_modal = gtk_column_view_get_columns( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	column_count = g_list_model_get_n_items( list_modal ) ;
	CallRuntimeFunction_int_SetIntValue( rt , out1 , column_count );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_GetRowCount;
int ZlangInvokeFunction_guitable_GetRowCount( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GListModel					*model = NULL ;
	int32_t						row_count ;

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	model = gtk_selection_get_model( selection_model ) ;
	row_count = g_list_model_get_n_items( model ) ;
	CallRuntimeFunction_int_SetIntValue( rt , out1 , row_count );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_GetData_int_int;
int ZlangInvokeFunction_guitable_GetData_int_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						row_no ;
	int32_t						col_no ;
	GListModel					*model = NULL ;
	RowObject					*row_datas = NULL ;
	int						nret = 0 ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & row_no );
	CallRuntimeFunction_int_GetIntValue( rt , in2 , & col_no );

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) );
	model = gtk_selection_get_model( selection_model ) ;
	row_datas = g_list_model_get_item( model , row_no-1 );
	if( col_no > row_datas->n_columns )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETERS_COUNT_NOT_MATCHED );
	}

	if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_INT )
	{
		nret = CloneObject( rt , & out1 , NULL , GetIntObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_int_SetIntValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.n );
	}
	else if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_DOUBLE )
	{
		nret = CloneObject( rt , & out1 , NULL , GetDoubleObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_double_SetDoubleValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.d );
	}
	else if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_STRING )
	{
		nret = CloneObject( rt , & out1 , NULL , GetStringObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_string_SetStringValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.str , STRLEN_OF_STRING );
	}
	else
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETER_TYPE_NOT_MATCHED );
	}
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_SetData_int_int_object;
int ZlangInvokeFunction_guitable_SetData_int_int_object( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						row_no ;
	int32_t						col_no ;
	GListModel					*model = NULL ;
	RowObject					*row_datas = NULL ;
	RowObject					*new_row_datas = NULL ;
	int32_t						c ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & row_no );
	CallRuntimeFunction_int_GetIntValue( rt , in2 , & col_no );

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) );
	model = gtk_selection_get_model( selection_model ) ;
	row_datas = g_list_model_get_item( model , row_no-1 );
	if( col_no > row_datas->n_columns )
	{
		UnreferObject( rt , out1 );
		return 0;
	}

	new_row_datas = row_object_new0( row_datas->n_columns ) ;
	if( new_row_datas == NULL )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
	}
	new_row_datas->n_columns = row_datas->n_columns ;
	for( c = 0 ; c < row_datas->n_columns ; c++ )
	{
		new_row_datas->col_datas[c].col_type = row_datas->col_datas[c].col_type ;
		if( c == col_no-1 )
		{
			if( row_datas->col_datas[c].col_type == ROW_DATA_TYPE_INT && IsTypeOf( rt , in3 , GetIntObjectInRuntimeObjectsHeap(rt) ) )
			{
				int32_t		row_col_n ;
				CallRuntimeFunction_int_GetIntValue( rt , in3 , & row_col_n );
				new_row_datas->col_datas[c].col_data.n = row_col_n ;
			}
			else if( row_datas->col_datas[c].col_type == ROW_DATA_TYPE_DOUBLE && IsTypeOf( rt , in3 , GetDoubleObjectInRuntimeObjectsHeap(rt) ) )
			{
				double		row_col_d ;
				CallRuntimeFunction_double_GetDoubleValue( rt , in3 , & row_col_d );
				new_row_datas->col_datas[c].col_data.d = row_col_d ;
			}
			else if( row_datas->col_datas[c].col_type == ROW_DATA_TYPE_STRING && IsTypeOf( rt , in3 , GetStringObjectInRuntimeObjectsHeap(rt) ) )
			{
				char		*row_col_str = NULL ;
				CallRuntimeFunction_string_GetStringValue( rt , in3 , & row_col_str , NULL );
				new_row_datas->col_datas[c].col_data.str = g_strdup( row_col_str ) ;
			}
			else
			{
				UnreferObject( rt , out1 );
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETER_TYPE_NOT_MATCHED );
			}
		}
		else
		{
			if( row_datas->col_datas[c].col_type == ROW_DATA_TYPE_INT )
			{
				new_row_datas->col_datas[c].col_data.n = row_datas->col_datas[c].col_data.n ;
			}
			else if( row_datas->col_datas[c].col_type == ROW_DATA_TYPE_DOUBLE )
			{
				new_row_datas->col_datas[c].col_data.d = row_datas->col_datas[c].col_data.d ;
			}
			else if( row_datas->col_datas[c].col_type == ROW_DATA_TYPE_STRING )
			{
				new_row_datas->col_datas[c].col_data.str = g_strdup( row_datas->col_datas[c].col_data.str ) ;
				if( new_row_datas->col_datas[c].col_data.str == NULL )
				{
					UnreferObject( rt , out1 );
					return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_OBJECT_FAILED );
				}
			}
			else
			{
				UnreferObject( rt , out1 );
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETER_TYPE_NOT_MATCHED );
			}
		}
	}

	g_list_store_splice( G_LIST_STORE(model) , row_no-1 , 1 , (gpointer[]) { new_row_datas } , 1 );

	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , TRUE );
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_GetSelectedRowNo;
int ZlangInvokeFunction_guitable_GetSelectedRowNo( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						row_no ;

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) );
	if( ! GTK_IS_SINGLE_SELECTION(selection_model) )
	{
		CallRuntimeFunction_int_SetIntValue( rt , out1 , -1 );
		return 0;
	}
	row_no = gtk_single_selection_get_selected( GTK_SINGLE_SELECTION(selection_model) ) ;
	CallRuntimeFunction_int_SetIntValue( rt , out1 , row_no+1 );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_GetSelectedRowText_int;
int ZlangInvokeFunction_guitable_GetSelectedRowData_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						col_no ;
	RowObject					*row_datas = NULL ;
	int						nret = 0 ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & col_no );

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	if( ! GTK_IS_SINGLE_SELECTION(selection_model) )
	{
		UnreferObject( rt , out1 );
		return 0;
	}
	row_datas = gtk_single_selection_get_selected_item( GTK_SINGLE_SELECTION(selection_model) ) ;
	if( col_no > row_datas->n_columns )
	{
		UnreferObject( rt , out1 );
		return 0;
	}

	if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_INT )
	{
		nret = CloneObject( rt , & out1 , NULL , GetIntObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_int_SetIntValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.n );
	}
	else if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_DOUBLE )
	{
		nret = CloneObject( rt , & out1 , NULL , GetDoubleObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_double_SetDoubleValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.d );
	}
	else if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_STRING )
	{
		nret = CloneObject( rt , & out1 , NULL , GetStringObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_string_SetStringValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.str , STRLEN_OF_STRING );
	}
	else
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETER_TYPE_NOT_MATCHED );
	}
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_IsRowSelected_int;
int ZlangInvokeFunction_guitable_IsRowSelected_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						row_no ;
	unsigned char					b ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & row_no );

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) );
	if( GTK_IS_SINGLE_SELECTION(selection_model) )
	{
		UnreferObject( rt , out1 );
		return 0;
	}
	b = gtk_selection_model_is_selected( selection_model , row_no-1 ) ;
	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , b );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_GetSelectedRowsCount;
int ZlangInvokeFunction_guitable_GetSelectedRowsCount( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						selected_row_count ;

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) );
	if( GTK_IS_SINGLE_SELECTION(selection_model) )
	{
		UnreferObject( rt , out1 );
		return 0;
	}
	GtkBitset *s = gtk_selection_model_get_selection( selection_model ) ;
	selected_row_count = (int32_t)gtk_bitset_get_size(s) ;
	gtk_bitset_unref(s);
	CallRuntimeFunction_int_SetIntValue( rt , out1 , selected_row_count );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guitable_GetSelectedRowsData_int_int;
int ZlangInvokeFunction_guitable_GetSelectedRowsData_int_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = & (guitable_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						selected_row_count ;
	int32_t						selected_row_no ;
	int32_t						row_no ;
	int32_t						col_no ;
	RowObject					*row_datas = NULL ;
	int						nret = 0 ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & selected_row_no );
	CallRuntimeFunction_int_GetIntValue( rt , in2 , & col_no );

	GtkSelectionModel *selection_model = gtk_column_view_get_model( GTK_COLUMN_VIEW(guitable_common->gtk_widget) ) ;
	if( GTK_IS_SINGLE_SELECTION(selection_model) )
	{
		UnreferObject( rt , out1 );
		return 0;
	}
	GtkBitset *s = gtk_selection_model_get_selection( selection_model ) ;
	selected_row_count = (int32_t)gtk_bitset_get_size(s) ;
	if( selected_row_no > selected_row_count )
	{
		gtk_bitset_unref(s);
		UnreferObject( rt , out1 );
		return 0;
	}
	row_no = (int32_t)gtk_bitset_get_nth( s , selected_row_no-1 ) ;
	gtk_bitset_unref(s);
	row_datas = g_list_model_get_item( G_LIST_MODEL(selection_model) , row_no );
	if( col_no > row_datas->n_columns )
	{
		UnreferObject( rt , out1 );
		return 0;
	}

	if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_INT )
	{
		nret = CloneObject( rt , & out1 , NULL , GetIntObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_int_SetIntValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.n );
	}
	else if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_DOUBLE )
	{
		nret = CloneObject( rt , & out1 , NULL , GetIntObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_double_SetDoubleValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.d );
	}
	else if( row_datas->col_datas[col_no-1].col_type == ROW_DATA_TYPE_STRING )
	{
		nret = CloneObject( rt , & out1 , NULL , GetStringObjectInRuntimeObjectsHeap(rt) ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return nret;
		}

		CallRuntimeFunction_string_SetStringValue( rt , out1 , row_datas->col_datas[col_no-1].col_data.str , STRLEN_OF_STRING );
	}
	else
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_PARAMETER_TYPE_NOT_MATCHED );
	}
	
	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guitable;
void *ZlangCreateDirectProperty_guitable( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable		*guitable_prop = NULL ;
	struct ZlangDirectProperty_guiwidget_common	*guitable_common = NULL ;
	
	guitable_prop = (struct ZlangDirectProperty_guitable *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guitable) ) ;
	if( guitable_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guitable_prop , 0x00 , sizeof(struct ZlangDirectProperty_guitable) );

	guitable_common = (struct ZlangDirectProperty_guiwidget_common *)guitable_prop ;
	guitable_common->gtk_widget_type_id = GTK_TYPE_COLUMN_VIEW ;

	INIT_ZLANGDIRECTPROPERTY_guiwidget_common(guitable)
	
	return guitable_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guitable;
void ZlangDestroyDirectProperty_guitable( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guitable	*guitable_direct_prop = GetObjectDirectProperty(obj) ;
	
	CLEAN_ZLANGDIRECTPROPERTY_guiwidget_common(guitable)

	ZLFREE( guitable_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guitable;
void ZlangSummarizeDirectPropertySize_guitable( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guitable) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guitable =
	{
		ZLANG_OBJECT_guitable , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guitable , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guitable , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guitable , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guitable;
struct ZlangObject *ZlangImportObject_guitable( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangObject	*prop = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guitable , & direct_funcs_guitable , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "SINGLE_SELECTION_MODAL") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUISELECTION_MODAL_SINGLE );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "MULTI_SELECTION_MODAL") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUISELECTION_MODAL_MULTI );
	SetConstantObject( prop );
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_Create_guiwindow_int , ZLANG_OBJECT_guitable , "Create" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_AppendColumns_vargs , ZLANG_OBJECT_guitable , "AppendColumns" , ZLANG_OBJECT_vargs,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_AppendRowDatas_vargs , ZLANG_OBJECT_guitable , "AppendRowDatas" , ZLANG_OBJECT_vargs,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_AppendRowDatas_array , ZLANG_OBJECT_guitable , "AppendRowDatas" , ZLANG_OBJECT_array,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_InsertRowDatas_int_array , ZLANG_OBJECT_guitable , "InsertRowDatas" , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_array,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guiwidget_all_common_functions( table )

	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guictl_all_common_functions( table )

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_RemoveRow_int , ZLANG_OBJECT_bool , "RemoveRow" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_RemoveAllRows , ZLANG_OBJECT_void , "RemoveAllRows" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_GetColumnCount , ZLANG_OBJECT_int , "GetColumnCount" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_GetRowCount , ZLANG_OBJECT_int , "GetRowCount" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_GetData_int_int , ZLANG_OBJECT_object , "GetData" , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_SetData_int_int_object , ZLANG_OBJECT_bool , "SetData" , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_object,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_GetSelectedRowNo , ZLANG_OBJECT_int , "GetSelectedRowNo" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_GetSelectedRowData_int , ZLANG_OBJECT_object , "GetSelectedRowData" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_IsRowSelected_int , ZLANG_OBJECT_bool , "IsRowSelected" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_GetSelectedRowsCount , ZLANG_OBJECT_int , "GetSelectedRowsCount" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guitable_GetSelectedRowsData_int_int , ZLANG_OBJECT_object , "GetSelectedRowsData" , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	return obj ;
}
